﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace tdgame {
	public class PolygonHelper {
		private Color[] ColorMap = new Color[256];
		WorldBuilder wb;

		public PolygonHelper(ref WorldBuilder _wb) {
			wb = _wb;
			FillColorMap();
		}

		public void CreateCell(int x, int y, Color color, ref List<VertexPositionNormalTextureColor> list) {
            //List<Vector3> vals = new List<Vector3> { wb.map[x, y], wb.map[x + 1, y], wb.map[x, y + 1], wb.map[x + 1, y + 1] };
			if ((int)wb.map[x, y].Y == (int)wb.map[x + 1, y + 1].Y) {
				CreateNewFace(wb.map[x, y], wb.map[x + 1, y], wb.map[x + 1, y + 1], color, ref list);
				CreateNewFace(wb.map[x, y], wb.map[x + 1, y + 1], wb.map[x, y + 1], color, ref list);
			}
			else {
				CreateNewFace(wb.map[x, y], wb.map[x + 1, y], wb.map[x, y + 1], color, ref list);
				CreateNewFace(wb.map[x + 1, y], wb.map[x + 1, y + 1], wb.map[x, y + 1], color, ref list);
			}
		}

		public void CreateNewFace(Vector3 vertex1, Vector3 vertex2, Vector3 vertex3, Color color, ref List<VertexPositionNormalTextureColor> list) {

			Vector3 normal = GetNormal(vertex1, vertex2, vertex3);

			if (color != Color.Transparent) {
				list.AddRange(new VertexPositionNormalTextureColor[] {
					new VertexPositionNormalTextureColor(vertex1, normal, color),
					new VertexPositionNormalTextureColor(vertex2,normal,color),
					new VertexPositionNormalTextureColor(vertex3,normal,color)
				});
			}
			else {
				list.AddRange(new VertexPositionNormalTextureColor[] {
					new VertexPositionNormalTextureColor(vertex1, normal, ColorAtHeight((int)vertex1.Y)),
					new VertexPositionNormalTextureColor(vertex2,normal,ColorAtHeight((int)vertex2.Y)),
					new VertexPositionNormalTextureColor(vertex3,normal,ColorAtHeight((int)vertex3.Y))
				});
			}

		}

		public void CreateLine(Vector3 vertex1, Vector3 vertex2, Color color, ref List<VertexPositionNormalTextureColor> list) {
			list.Add(new VertexPositionNormalTextureColor(vertex1, Vector3.Up, color));
			list.Add(new VertexPositionNormalTextureColor(vertex2, Vector3.Up, color));
		}

		public Vector3 GetNormal(Vector3 vertex1, Vector3 vertex2, Vector3 vertex3) {
			Vector3 edge1 = vertex2 - vertex1,
				edge2 = vertex3 - vertex1;

			Vector3 normal = Vector3.Cross(edge2, edge1);
			normal.Normalize();

			return normal;
		}

		public void FillColorMap() {

			ColorMap = new Color[] {
				Color.FromNonPremultiplied(53,27,0 , 255), 
				Color.FromNonPremultiplied(53,27,0 , 255), 
				Color.FromNonPremultiplied(54,27,0 , 255), 
				Color.FromNonPremultiplied(55,28,0 , 255), 
				Color.FromNonPremultiplied(56,28,0 , 255), 
				Color.FromNonPremultiplied(57,29,0 , 255), 
				Color.FromNonPremultiplied(57,29,0 , 255), 
				Color.FromNonPremultiplied(58,29,0 , 255), 
				Color.FromNonPremultiplied(59,30,0 , 255), 
				Color.FromNonPremultiplied(60,30,0 , 255), 
				Color.FromNonPremultiplied(61,31,0 , 255), 
				Color.FromNonPremultiplied(62,31,0 , 255), 
				Color.FromNonPremultiplied(62,31,0 , 255), 
				Color.FromNonPremultiplied(63,32,0 , 255), 
				Color.FromNonPremultiplied(64,32,0 , 255), 
				Color.FromNonPremultiplied(65,33,0 , 255), 
				Color.FromNonPremultiplied(66,33,0 , 255), 
				Color.FromNonPremultiplied(67,34,0 , 255), 
				Color.FromNonPremultiplied(67,34,0 , 255), 
				Color.FromNonPremultiplied(68,34,0 , 255), 
				Color.FromNonPremultiplied(69,35,0 , 255), 
				Color.FromNonPremultiplied(70,35,0 , 255), 
				Color.FromNonPremultiplied(71,36,0 , 255), 
				Color.FromNonPremultiplied(71,36,0 , 255), 
				Color.FromNonPremultiplied(72,36,0 , 255), 
				Color.FromNonPremultiplied(73,37,0 , 255), 
				Color.FromNonPremultiplied(74,37,0 , 255), 
				Color.FromNonPremultiplied(75,38,0 , 255), 
				Color.FromNonPremultiplied(76,38,0 , 255), 
				Color.FromNonPremultiplied(76,38,0 , 255), 
				Color.FromNonPremultiplied(77,39,0 , 255), 
				Color.FromNonPremultiplied(78,39,0 , 255), 
				Color.FromNonPremultiplied(79,40,0 , 255), 
				Color.FromNonPremultiplied(80,40,0 , 255), 
				Color.FromNonPremultiplied(81,41,0 , 255), 
				Color.FromNonPremultiplied(81,41,0 , 255), 
				Color.FromNonPremultiplied(82,41,0 , 255), 
				Color.FromNonPremultiplied(83,42,0 , 255), 
				Color.FromNonPremultiplied(84,42,0 , 255), 
				Color.FromNonPremultiplied(85,43,0 , 255), 
				Color.FromNonPremultiplied(86,43,0 , 255), 
				Color.FromNonPremultiplied(86,43,0 , 255), 
				Color.FromNonPremultiplied(87,44,0 , 255), 
				Color.FromNonPremultiplied(88,44,0 , 255), 
				Color.FromNonPremultiplied(89,45,0 , 255), 
				Color.FromNonPremultiplied(90,45,0 , 255), 
				Color.FromNonPremultiplied(90,45,0 , 255), 
				Color.FromNonPremultiplied(91,46,0 , 255), 
				Color.FromNonPremultiplied(92,46,0 , 255), 
				Color.FromNonPremultiplied(93,47,0 , 255), 
				Color.FromNonPremultiplied(94,47,0 , 255), 
				Color.FromNonPremultiplied(95,48,0 , 255), 
				Color.FromNonPremultiplied(95,48,0 , 255), 
				Color.FromNonPremultiplied(96,48,0 , 255), 
				Color.FromNonPremultiplied(97,49,0 , 255), 
				Color.FromNonPremultiplied(98,49,0 , 255), 
				Color.FromNonPremultiplied(99,50,0 , 255), 
				Color.FromNonPremultiplied(100,50,0 , 255), 
				Color.FromNonPremultiplied(100,50,0 , 255), 
				Color.FromNonPremultiplied(101,51,0 , 255), 
				Color.FromNonPremultiplied(102,51,0 , 255), 
				Color.FromNonPremultiplied(103,52,0 , 255), 
				Color.FromNonPremultiplied(104,52,0 , 255), 
				Color.FromNonPremultiplied(104,52,0 , 255), 
				Color.FromNonPremultiplied(105,53,0 , 255), 
				Color.FromNonPremultiplied(106,53,0 , 255), 
				Color.FromNonPremultiplied(107,54,0 , 255), 
				Color.FromNonPremultiplied(108,54,0 , 255), 
				Color.FromNonPremultiplied(109,55,0 , 255), 
				Color.FromNonPremultiplied(109,55,0 , 255), 
				Color.FromNonPremultiplied(110,55,0 , 255), 
				Color.FromNonPremultiplied(111,56,0 , 255), 
				Color.FromNonPremultiplied(112,56,0 , 255), 
				Color.FromNonPremultiplied(113,57,0 , 255), 
				Color.FromNonPremultiplied(114,57,0 , 255), 
				Color.FromNonPremultiplied(114,57,0 , 255), 
				Color.FromNonPremultiplied(115,58,0 , 255), 
				Color.FromNonPremultiplied(116,58,0 , 255), 
				Color.FromNonPremultiplied(117,59,0 , 255), 
				Color.FromNonPremultiplied(118,59,0 , 255), 
				Color.FromNonPremultiplied(119,60,0 , 255), 
				Color.FromNonPremultiplied(123,68,10 , 255), 
				Color.FromNonPremultiplied(127,76,20 , 255), 
				Color.FromNonPremultiplied(131,85,31 , 255), 
				Color.FromNonPremultiplied(136,93,41 , 255), 
				Color.FromNonPremultiplied(140,102,51 , 255), 
				Color.FromNonPremultiplied(144,110,62 , 255), 
				Color.FromNonPremultiplied(149,119,72 , 255), 
				Color.FromNonPremultiplied(153,127,82 , 255), 
				Color.FromNonPremultiplied(157,136,93 , 255), 
				Color.FromNonPremultiplied(162,144,103 , 255), 
				Color.FromNonPremultiplied(166,152,113 , 255), 
				Color.FromNonPremultiplied(170,161,124 , 255), 
				Color.FromNonPremultiplied(174,169,134 , 255), 
				Color.FromNonPremultiplied(179,178,144 , 255), 
				Color.FromNonPremultiplied(183,186,155 , 255), 
				Color.FromNonPremultiplied(187,195,165 , 255), 
				Color.FromNonPremultiplied(192,203,175 , 255), 
				Color.FromNonPremultiplied(196,212,186 , 255), 
				Color.FromNonPremultiplied(200,220,196 , 255), 
				Color.FromNonPremultiplied(205,229,207 , 255), 
				Color.FromNonPremultiplied(187,212,178 , 255), 
				Color.FromNonPremultiplied(169,195,149 , 255), 
				Color.FromNonPremultiplied(151,178,120 , 255), 
				Color.FromNonPremultiplied(133,161,91 , 255), 
				Color.FromNonPremultiplied(100,139,63 , 255), 
				Color.FromNonPremultiplied(68,118,36 , 255), 
				Color.FromNonPremultiplied(37,98,10 , 255), 
				Color.FromNonPremultiplied(35,95,9 , 255), 
				Color.FromNonPremultiplied(33,93,8 , 255), 
				Color.FromNonPremultiplied(32,90,8 , 255), 
				Color.FromNonPremultiplied(30,88,7 , 255), 
				Color.FromNonPremultiplied(28,85,7 , 255), 
				Color.FromNonPremultiplied(27,83,6 , 255), 
				Color.FromNonPremultiplied(25,80,6 , 255), 
				Color.FromNonPremultiplied(23,78,5 , 255), 
				Color.FromNonPremultiplied(22,75,5 , 255), 
				Color.FromNonPremultiplied(20,73,4 , 255), 
				Color.FromNonPremultiplied(19,71,4 , 255), 
				Color.FromNonPremultiplied(38,98,6 , 255), 
				Color.FromNonPremultiplied(57,126,8 , 255), 
				Color.FromNonPremultiplied(77,154,10 , 255), 
				Color.FromNonPremultiplied(73,149,8 , 255), 
				Color.FromNonPremultiplied(69,145,7 , 255), 
				Color.FromNonPremultiplied(65,140,6 , 255), 
				Color.FromNonPremultiplied(61,136,5 , 255), 
				Color.FromNonPremultiplied(55,129,5 , 255), 
				Color.FromNonPremultiplied(50,123,6 , 255), 
				Color.FromNonPremultiplied(45,117,6 , 255), 
				Color.FromNonPremultiplied(40,111,7 , 255), 
				Color.FromNonPremultiplied(38,106,6 , 255), 
				Color.FromNonPremultiplied(36,102,6 , 255), 
				Color.FromNonPremultiplied(34,98,5 , 255), 
				Color.FromNonPremultiplied(32,94,5 , 255), 
				Color.FromNonPremultiplied(30,91,4 , 255), 
				Color.FromNonPremultiplied(29,88,3 , 255), 
				Color.FromNonPremultiplied(27,85,2 , 255), 
				Color.FromNonPremultiplied(26,83,2 , 255), 
				Color.FromNonPremultiplied(40,88,5 , 255), 
				Color.FromNonPremultiplied(55,94,8 , 255), 
				Color.FromNonPremultiplied(70,99,11 , 255), 
				Color.FromNonPremultiplied(85,105,14 , 255), 
				Color.FromNonPremultiplied(79,98,14 , 255), 
				Color.FromNonPremultiplied(74,92,14 , 255), 
				Color.FromNonPremultiplied(69,85,14 , 255), 
				Color.FromNonPremultiplied(64,79,14 , 255), 
				Color.FromNonPremultiplied(62,77,13 , 255), 
				Color.FromNonPremultiplied(60,75,13 , 255), 
				Color.FromNonPremultiplied(58,74,12 , 255), 
				Color.FromNonPremultiplied(56,72,12 , 255), 
				Color.FromNonPremultiplied(55,71,12 , 255), 
				Color.FromNonPremultiplied(56,73,14 , 255), 
				Color.FromNonPremultiplied(58,76,16 , 255), 
				Color.FromNonPremultiplied(60,79,19 , 255), 
				Color.FromNonPremultiplied(62,82,21 , 255), 
				Color.FromNonPremultiplied(64,85,24 , 255), 
				Color.FromNonPremultiplied(60,82,25 , 255), 
				Color.FromNonPremultiplied(56,80,26 , 255), 
				Color.FromNonPremultiplied(52,78,27 , 255), 
				Color.FromNonPremultiplied(48,76,28 , 255), 
				Color.FromNonPremultiplied(45,74,29 , 255), 
				Color.FromNonPremultiplied(41,68,27 , 255), 
				Color.FromNonPremultiplied(37,63,26 , 255), 
				Color.FromNonPremultiplied(34,59,25 , 255), 
				Color.FromNonPremultiplied(30,53,24 , 255), 
				Color.FromNonPremultiplied(26,49,23 , 255), 
				Color.FromNonPremultiplied(23,44,22 , 255), 
				Color.FromNonPremultiplied(21,41,19 , 255), 
				Color.FromNonPremultiplied(20,38,17 , 255), 
				Color.FromNonPremultiplied(18,35,15 , 255), 
				Color.FromNonPremultiplied(17,33,13 , 255), 
				Color.FromNonPremultiplied(18,35,14 , 255), 
				Color.FromNonPremultiplied(19,37,16 , 255), 
				Color.FromNonPremultiplied(20,39,18 , 255), 
				Color.FromNonPremultiplied(21,41,20 , 255), 
				Color.FromNonPremultiplied(23,44,22 , 255), 
				Color.FromNonPremultiplied(26,47,27 , 255), 
				Color.FromNonPremultiplied(29,50,32 , 255), 
				Color.FromNonPremultiplied(32,53,37 , 255), 
				Color.FromNonPremultiplied(35,56,42 , 255), 
				Color.FromNonPremultiplied(39,60,47 , 255), 
				Color.FromNonPremultiplied(42,60,49 , 255), 
				Color.FromNonPremultiplied(45,61,51 , 255), 
				Color.FromNonPremultiplied(49,62,54 , 255), 
				Color.FromNonPremultiplied(52,62,56 , 255), 
				Color.FromNonPremultiplied(55,63,58 , 255), 
				Color.FromNonPremultiplied(59,64,61 , 255), 
				Color.FromNonPremultiplied(59,65,62 , 255), 
				Color.FromNonPremultiplied(60,66,63 , 255), 
				Color.FromNonPremultiplied(61,68,64 , 255), 
				Color.FromNonPremultiplied(62,69,65 , 255), 
				Color.FromNonPremultiplied(63,70,65 , 255), 
				Color.FromNonPremultiplied(64,72,67 , 255), 
				Color.FromNonPremultiplied(68,75,70 , 255), 
				Color.FromNonPremultiplied(72,79,74 , 255), 
				Color.FromNonPremultiplied(76,82,78 , 255), 
				Color.FromNonPremultiplied(80,86,82 , 255), 
				Color.FromNonPremultiplied(84,89,86 , 255), 
				Color.FromNonPremultiplied(89,93,90 , 255), 
				Color.FromNonPremultiplied(100,106,101 , 255), 
				Color.FromNonPremultiplied(111,119,112 , 255), 
				Color.FromNonPremultiplied(122,133,123 , 255), 
				Color.FromNonPremultiplied(133,146,135 , 255), 
				Color.FromNonPremultiplied(144,160,146 , 255), 
				Color.FromNonPremultiplied(155,173,157 , 255), 
				Color.FromNonPremultiplied(166,187,169 , 255), 
				Color.FromNonPremultiplied(170,189,173 , 255), 
				Color.FromNonPremultiplied(174,192,177 , 255), 
				Color.FromNonPremultiplied(178,194,181 , 255), 
				Color.FromNonPremultiplied(183,197,185 , 255), 
				Color.FromNonPremultiplied(187,200,189 , 255), 
				Color.FromNonPremultiplied(191,202,193 , 255), 
				Color.FromNonPremultiplied(196,205,197 , 255), 
				Color.FromNonPremultiplied(200,207,201 , 255), 
				Color.FromNonPremultiplied(204,210,205 , 255), 
				Color.FromNonPremultiplied(209,213,210 , 255), 
				Color.FromNonPremultiplied(212,216,213 , 255), 
				Color.FromNonPremultiplied(216,219,217 , 255), 
				Color.FromNonPremultiplied(219,222,220 , 255), 
				Color.FromNonPremultiplied(223,226,224 , 255), 
				Color.FromNonPremultiplied(227,229,227 , 255), 
				Color.FromNonPremultiplied(230,232,231 , 255), 
				Color.FromNonPremultiplied(234,236,234 , 255), 
				Color.FromNonPremultiplied(237,239,238 , 255), 
				Color.FromNonPremultiplied(241,242,241 , 255), 
				Color.FromNonPremultiplied(245,246,245 , 255), 
				Color.FromNonPremultiplied(245,246,245 , 255), 
				Color.FromNonPremultiplied(246,247,246 , 255), 
				Color.FromNonPremultiplied(247,247,247 , 255), 
				Color.FromNonPremultiplied(247,248,247 , 255), 
				Color.FromNonPremultiplied(248,249,248 , 255), 
				Color.FromNonPremultiplied(249,249,249 , 255), 
				Color.FromNonPremultiplied(249,250,249 , 255), 
				Color.FromNonPremultiplied(250,250,250 , 255), 
				Color.FromNonPremultiplied(251,251,251 , 255), 
				Color.FromNonPremultiplied(251,252,251 , 255), 
				Color.FromNonPremultiplied(252,252,252 , 255), 
				Color.FromNonPremultiplied(253,253,253 , 255), 
				Color.FromNonPremultiplied(253,253,253 , 255), 
				Color.FromNonPremultiplied(254,254,254 , 255), 
				Color.FromNonPremultiplied(255,255,255 , 255), 
				Color.FromNonPremultiplied(255,255,255 , 255), 
				Color.FromNonPremultiplied(255,255,255 , 255), 
				Color.FromNonPremultiplied(255,255,255 , 255), 
				Color.FromNonPremultiplied(255,255,255 , 255), 
				Color.FromNonPremultiplied(255,255,255 , 255), 
				Color.FromNonPremultiplied(255,255,255 , 255), 
				Color.FromNonPremultiplied(255,255,255 , 255), 
				Color.FromNonPremultiplied(255,255,255 , 255), 
				Color.FromNonPremultiplied(255,255,255 , 255), 
				Color.FromNonPremultiplied(255,255,255 , 255), 
				Color.FromNonPremultiplied(255,255,255 , 255), 
				Color.FromNonPremultiplied(255,255,255 , 255), 
				Color.FromNonPremultiplied(255,255,255 , 255), 
				Color.FromNonPremultiplied(255,255,255 , 255), 
				Color.FromNonPremultiplied(255,255,255, 255)
			};

			//List<Color> cols = new List<Color>();
			//string[] colList = colormap.Split("\n".ToCharArray());

			//foreach (string s in colList) {
			//    string[] values = s.Split(',');
			//    Color c = Color.FromNonPremultiplied(int.Parse(values[0]), int.Parse(values[1]), int.Parse(values[2]), 255);
			//    cols.Add(c);
			//}
			//ColorMap = cols.ToArray();
		}

		public void CreateTower(int x, int y, ref List<VertexPositionNormalTextureColor> list) {
			float ht = wb.map[x, y].Y;
			wb.cellMap[x, y].HasTower = true;
			//south wall
			CreateNewFace(
				new Vector3(wb.map[x, y + 1].X, ht, wb.map[x, y + 1].Z),
				new Vector3(wb.map[x + 1, y + 1].X, ht + 20f, wb.map[x + 1, y + 1].Z),
				new Vector3(wb.map[x + 1, y + 1].X, ht, wb.map[x + 1, y + 1].Z),
				Color.LightGray, ref list);
			CreateNewFace(
				new Vector3(wb.map[x, y + 1].X, ht, wb.map[x, y + 1].Z),
				new Vector3(wb.map[x, y + 1].X, ht + 20f, wb.map[x, y + 1].Z),
				new Vector3(wb.map[x + 1, y + 1].X, ht + 20f, wb.map[x + 1, y + 1].Z),
				Color.LightGray, ref list);

			//north wall
			CreateNewFace(
				new Vector3(wb.map[x + 1, y].X, ht, wb.map[x + 1, y].Z),
				new Vector3(wb.map[x, y].X, ht + 20f, wb.map[x, y].Z),
				new Vector3(wb.map[x, y].X, ht, wb.map[x, y].Z),
				Color.LightGray, ref list);
			CreateNewFace(
				new Vector3(wb.map[x + 1, y].X, ht, wb.map[x + 1, y].Z),
				new Vector3(wb.map[x + 1, y].X, ht + 20f, wb.map[x + 1, y].Z),
				new Vector3(wb.map[x, y].X, ht + 20f, wb.map[x, y].Z),
				Color.LightGray, ref list);

			//east wall
			CreateNewFace(
				new Vector3(wb.map[x + 1, y].X, ht + 20f, wb.map[x + 1, y].Z),
				new Vector3(wb.map[x + 1, y + 1].X, ht, wb.map[x + 1, y + 1].Z),
				new Vector3(wb.map[x + 1, y + 1].X, ht + 20f, wb.map[x + 1, y + 1].Z),
				Color.LightGray, ref list);
			CreateNewFace(
				new Vector3(wb.map[x + 1, y + 1].X, ht, wb.map[x + 1, y + 1].Z),
				new Vector3(wb.map[x + 1, y].X, ht + 20f, wb.map[x + 1, y].Z),
				new Vector3(wb.map[x + 1, y].X, ht, wb.map[x + 1, y].Z),
				Color.LightGray, ref list);

			//west
			CreateNewFace(
				new Vector3(wb.map[x, y + 1].X, ht, wb.map[x, y + 1].Z),
				new Vector3(wb.map[x, y].X, ht + 20f, wb.map[x, y].Z),
				new Vector3(wb.map[x, y + 1].X, ht + 20f, wb.map[x, y + 1].Z),
				Color.LightGray, ref list);
			CreateNewFace(
				new Vector3(wb.map[x, y].X, ht, wb.map[x, y].Z),
				new Vector3(wb.map[x, y].X, ht + 20f, wb.map[x, y].Z),
				new Vector3(wb.map[x, y + 1].X, ht, wb.map[x, y + 1].Z),
				Color.LightGray, ref list);

			//top
			CreateNewFace(
				new Vector3(wb.map[x, y].X, ht + 20f, wb.map[x, y].Z),
				new Vector3(wb.map[x + 1, y].X, ht + 20f, wb.map[x + 1, y].Z),
				new Vector3(wb.map[x + 1, y + 1].X, ht + 20f, wb.map[x + 1, y + 1].Z),
				Color.LightGray, ref list);
			CreateNewFace(
				new Vector3(wb.map[x, y].X, ht + 20f, wb.map[x, y].Z),
				new Vector3(wb.map[x + 1, y + 1].X, ht + 20f, wb.map[x + 1, y + 1].Z),
				new Vector3(wb.map[x, y + 1].X, ht + 20f, wb.map[x, y + 1].Z),
				Color.LightGray, ref list);
		}

		public void DrawPath(List<Vector3> pts, Color color, ref List<VertexPositionNormalTextureColor> list) {
			for (int i = 0; i < (pts.Count - 1); i++) {
				Vector3 pt = pts[i],
					pt2 = pts[i + 1];

                CreateLine(new Vector3((pt.X * 5) + 2.5f - (wb.WorldSize / 2),
						pt.Y,
                        (pt.Z * 5) + 2.5f - (wb.WorldSize / 2)),
                    new Vector3((pt2.X * 5) + 2.5f - (wb.WorldSize / 2),
						pt2.Y,
                        (pt2.Z * 5) + 2.5f - (wb.WorldSize / 2)),
						color, ref list);
			}
		}

		public Color ColorAtHeight(int height) {
			if (height < ColorMap.Count())
				return ColorMap[height];
			else
				return Color.White;
		}
	}
}
